#include <iostream>

#include "nature.hpp"

int main()
{
    srandom(time(NULL));
    Nature *nature = Nature::get_instance();

    int w = 0, s = 0, g = 0;
    do
    {
        std::cout << "初始化草原，请按顺序输入狼、羊、草的数量，以空格分割: " << std::endl;
        // TODO 这里提供选择加载已有数据的功能
        std::cin >> w >> s >> g;
        if ((w + s + g) > 10)
        {
            std::cout << "输入的数量太多了，请重新输入。" << std::endl;
            continue;
        }
    } while (0);

    std::cout << "将创建如下数目: " << w << ", " << s << ", " << g << std::endl;

    nature->init(w, s, g);

    bool quit = false;
    do
    {
        std::cout << "\n输入要执行的动作："
                  << "    r: 运行一轮;  "
                  << "    p: 打印当前世界;  "
                  << "    s: 保存当前状态;  "
                  << "    l: 加载保存的数据;  "
                  << "    e: 打印所有事件;  "
                  << "    q: 退出程序;"
                  << std::endl;

        char cmd = 'q';
        std::cin >> cmd;
        switch (cmd)
        {
        case 'r':
            nature->run();
            break;
        case 'p':
            nature->print();
            continue;
        case 's':
            nature->save("./nature.data");
            break;
        case 'l':
            nature->load("./nature.data");
            break;
        case 'e':
            nature->report();
            break;
        case 'q':
            quit = true;
            break;
        default:
            std::cout << "无效的命令，请重新输入";
            break;
        }
    } while (!quit);
    return 0;
}